package wyf.ytl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

public class XMLPullParse {

	Resources res;
	XmlResourceParser picParser;
	
	public XMLPullParse(Resources res) throws XmlPullParserException,
			IOException {
		this.res = res;

	}

	public ArrayList<Card> parseStart_1() throws XmlPullParserException, IOException {
		picParser = res.getXml(R.xml.cards);
		picParser.next();
		int eventType = picParser.getEventType();
		Card card;
		int n = 0;
		ArrayList<Card> cards = new ArrayList<Card>(200);
		while (eventType != XmlPullParser.END_DOCUMENT) {
			if (eventType == XmlPullParser.START_DOCUMENT) {
			} else if (eventType == XmlPullParser.START_TAG) {
				if ("item".equals(picParser.getName())) {
					card = new Card();
					card.id = picParser.getAttributeValue(null, "id");
					card.group = picParser.getAttributeValue(null, "group");
					card.picsrc = "cardpic/"+card.group+"/" + card.id + ".jpg";
					card.pic = BitmapFactory.decodeStream(res.getAssets().open(
							card.picsrc));
					
					cards.add(card);
					n++;
					
				}
			} else if (eventType == XmlPullParser.END_TAG) {
			} else if (eventType == XmlPullParser.TEXT) {
			} else if (eventType == XmlPullParser.END_DOCUMENT) {

			}
			eventType = picParser.next();
		}
		return cards;

	}

}